/*
 * Copyright 2022 The Open Islands Authors. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.openislands.oi.constant;

import java.util.HashMap;
import java.util.Map;

public enum DAGSchedulingState {
    SUCCESS(1000, "success"),
    NO_RESOURCE(2000, "no resource"),
    PASS(3000, "pass dag node"),
    NO_NEXT(4000, "no next"),
    HAVE_NEXT(5000, "have next"),
    FAILED(6000, "failed"),
    ;

    private final static Map<Integer, DAGSchedulingState> BY_CODE = new HashMap<>();
    static {
        for (DAGSchedulingState e: values()
        ) {
            BY_CODE.put(e.getCode(), e);
        }
    }
    private final int code;
    private final String name;

    DAGSchedulingState(int code, String name){
       this.code = code;
       this.name = name;
    }

    public static DAGSchedulingState valueByCode(int code){
        return BY_CODE.get(code);
    }

    public int getCode() {
        return code;
    }

    public String getName() {
        return name;
    }

    public static DAGSchedulingState byCode(int code){
        return values()[code / 1000 % values().length];
    }
}
